"""
    xpath   使用其他方式无法定位时，可以选择xpath定位
    xpath表示元素在html中的路径，根据路径定位
        绝对路径    根目录一直向下到定位元素    /html/body/div/h1   元素发生变化绝对路径就会改变
        相对路径

"""
from time import sleep
from selenium import webdriver
from selenium.webdriver.common.by import By
#创建一个浏览器实例
#driver = webdriver.Chrome()
driver = webdriver.Edge()
driver.get("http://www.baidu.com")
# input()
#/html/body/div/div[2]/div[2]/a[2]
# /html/body/div[1]/div[1]/div[5]/div/div/form/span[1]/input
# a = driver.find_element(By.XPATH,"/html/body/div[1]/div[1]/div[5]/div/div/form/span[1]/input")
# a.send_keys("Xpath是什么？")
# print(a.get_dom_attribute("id"))
# sleep(2)
#
# a = driver.find_element(By.XPATH,'//*[@id="kw"]')
# a.send_keys("呀呀呀呀")
# print(a.get_dom_attribute("id"))
# sleep(2)
#<input type="text" class="s_ipt" name="wd" id="kw" maxlength="100" autocomplete="off">
#<input id="input" class="truncate" type="search" autocomplete="off" spellcheck="false" role="combobox" aria-controls="matches" aria-expanded="false" aria-description="" placeholder="在 Google 中搜索，或输入网址" aria-live="polite">
# /html/body/div/div[2]/div[5]/div[1]/div/form/span[1]/input
# <input type="text" class="s_ipt" name="wd" id="kw" maxlength="100" autocomplete="off">
a = driver.find_element(By.XPATH,'//*[@maxlength="255" and @autocomplete="off"]')
a.send_keys("asdjgujhga")
print(a.get_dom_attribute("id"))
sleep(2)
